<?php

class quanModule extends Module {
	/*
	 * 在构造函数中装载所依赖的类或其他文件
	*/
	function __construct() {
		$this->includePhp('quan', 'quan');
	}


	/*
	 * 调用插件资源
	*/
	public function call($user, $method, $param) {
		//检查用户
		$customerId = Session::$user['customerId'];
		Session::switchCustomer(0);
		$uid = Session::$user['userId'];
		$quanUserModel=M("quan_user");
		Session::switchCustomer($customerId);
		$fromUId=$param->fromUId;
		$fromGuid=$param->fromGuid;
		$allowMethod="home|index|account|order|orderAward|
		award|cashPage|getMiFList|miPage|index_pro|shopIndex|shopStart
		|balance|getBalanceList|mienlist";
		if(strpos($allowMethod,$method) && (!$fromUId && !$fromGuid)){
			if(!$uid){
				Output::instance()->resultCode(1,"无访问权限");
				return;
			}
//			$user=$quanUserModel->where("uid=$uid")->select();
//			if(!$user || count($user) < 1){
//				Output::instance()->resultCode(1,"无访问权限");
//				return;
//			}
			//判断是否主公身份
			if($param){
				$uType=$param->uType;
				if($uType && $uType==1){
					if($user["identity"] == 1){
						Output::instance()->resultCode(1,"无访问权限");
						return;
					}
				}
			}
		}
		switch ($method) {
			case 'index':
				quan::userIndex($param);
				break;
			case 'getIndexData':
				quan::getIndexData($param);
				break;
			case 'userIndex':
				quan::userIndex($param);
				break;
			case 'home':
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::home($param);
				break;
			case 'saveUser':
				quan::saveUser($param);
				break;
			case 'index_pro':
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::index_pro($param);
				break;
			case 'miu_pro':
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::miu_pro($param);
				break;
			case 'getProList':
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getProList($qId,$param->start,$param->limit);
				break;
			case 'getMiuProList':
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getMiuProList($qId,$param->start,$param->limit);
				break;
			case 'bind':
				quan::bind();
				break;
			case 'getQuan':
				quan::getQuan($param);
				break;
			case 'getQuanList':
				quan::getQuanList($param->start,$param->limit);
				break;
			case 'sendSmsCode':
				$mobile = $param->mobile;
				if (!isset($mobile)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::sendSmsCode($mobile,$param->isCheckExist);
				break;
			case 'saveBind':
				$mobile = $param->mobile;
				$code=$param->code;
				if (!isset($mobile)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (!isset($code)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::saveBind($mobile,$code);
				break;
			case 'getGuideView':
				$sId=$param->id;
				if (!isset($sId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getGuideView($param);
				break;
			case 'getGuideViewImgs':
				$sId=$param->sId;
				if (!isset($sId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getGuideViewImgs($param);
				break;
			case 'addVisit':
				return quan::addVisit($param);
				break;
			case 'verifyCode':
				quan::verifyCode($param);
				break;
			case 'saveShare':
				$sId=$param->sId;
				$qId=$param->qId;
				if (!isset($sId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::saveShare($param);
				break;
			case 'order':
				quan::orderPage($param);
				break;
			case 'orderAward':
				quan::orderPageAward($param);
				break;
			case "getOrderList":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getOrderList($param->qId,$param->type,$param->start,$param->limit,$param->status,$param->search,
					$param->saleSource, $param->orderType);
				break;
			case "getOrderDetail":
				$oid=$param->oid;
				if (!isset($oid)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getOrderDetail($oid,$param->uType,$param->fromUId);
				break;
			case "shopIndex":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::shopIndex($param);
				break;
			case "getShopPro":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getShopPro($qId,$param->start,$param->limit,$param->fromUId);
				break;
			case "award":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::quanAwardIndex($param);
				break;
			case "balance":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::balanceIndex($param);
				break;
			case "getBalanceSum":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getBalanceSum($param);
				break;
			case "getBalanceList":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getBalanceList($param);
				break;
			case "miPage":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::miPage($param);
				break;
			case "getMiFList":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getMiFList($qId,$param->status,$param->start,$param->limit,$param->search,$param->order);
				break;
			case "cashPage":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::cashPage($param);
				break;
			case "saveCash":
				$qId=$param->qId;
				$cashNum=$param->cashNum;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (!isset($cashNum)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::saveCash($param);
				break;
			case "addQuanUser":
				$qId=$param->qId;
				$phone=$param->phone;
				$fullName=$param->fullName;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (!isset($fullName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::addQuanUser($param);
				break;
			case "changeQuanUserDeleted":
				$id=$param->id;
				if (!isset($id)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::changeQuanUserDeleted($param);
				break;
			case "auditQuanUser":
				$id=$param->id;
				if (!isset($id)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::auditQuanUser($param);
				break;
			 case 'getMiContent':
		        quan::getMiContent($param);
		        break;
			 case 'goToCustomer':
			 	quan::goToCustomer($param);
			        break;
			 case 'auth':
			 	quan::auth($param);
			        break;
			 case 'mienlist':
			 	quan::getMienlistPage($param);
			        break;
			 case 'activitylist':
			 	quan::getActivitylistPage($param);
			        break;
			 case 'miendetail':
			 	quan::getMiendetailPage($param);
			        break;
			 case 'mireg':
			 	quan::getMiregPage($param);
			        break;
			 case 'regQuanSave':
			 	quan::regQuanSave($param);
			    break;
			case 'shopStart':
			 	$qId=$param->qId;
			    if (!isset($qId)) {
			         Output::instance()->resultCode(code_lackof_param);
			         return;
			    }
			 	quan::shopStart($param);
			    break;
			case "getShopStartList":
				$qId=$param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getShopStartList($qId,$param->start,$param->limit,$param->fromUId);
				break;
			case 'myRecommend':
			 	$qId=$param->quanId;
			    if (!isset($qId)) {
			         Output::instance()->resultCode(code_lackof_param);
			         return;
			    }
			 	quan::myRecommend($param);
			    break;
			case 'getActivilyList':
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				quan::getActivilyList($param,$param->start,$param->limit);
			    break;
			case 'subscribeRegQuanUser':
				quan::subscribeRegQuanUser($param);
			    break;
			case 'payContent':
				quan::payContent($param);
				break;
			//营销圈进入首页前逻辑判断
			case 'judgeUserStatus':
				quan::judgeUserStatus($param);
				break;
			//营销圈购买说明页详细信息返回
			case 'payContentDetail':
				quan::payContentDetail($param);
				break;
			case 'withdrawConfig':
				$qid = $param->qId;
				quan::withdrawConfig($qid);
				break;
			case 'addUserBankAccount':
				$bankAccountName = $param->bankAccountName;
				$bankCardNum = $param->bankCardNum;
				$bankCardName = $param->bankCardName;
				$bankWxNum = $param->bankWxNum;
				$bankPicUrl = $param->bankPicUrl;
				quan::addUserBankAccount($bankAccountName,$bankCardNum,$bankCardName,$bankWxNum,$bankPicUrl);
				break;
			case 'wxPayBankList':
				quan::wxPayBankList();
				break;
			case 'deleteUserBankAccount':
				$index = $param->index;
				quan::deleteUserBankAccount($index);
				break;
            case 'whiteListJudge':
                $qid = $param->qid;
                $phone = $param->phone;
                quan::whiteListJudge($qid,$phone);
                break;
		}
	}
}


$module = new quanModule();
Module::addModule($module);
?>